<?php
/**
 * Created by PhpStorm.
 * User: hehecat
 * Date: 2018/8/30
 * Time: 15:23
 */

namespace app\admin\model;


use think\Db;
use think\Model;

class gameModel extends Model {

    public function getGame($admin_id) {
        $club_id = Db::table('admin')->where('adminid',$admin_id)->find()['clubid'];
        $club = Db::table('game')->where('clubid',$club_id)->select();
        return $club;
    }

    public function getGameImg($game_id) {
        $game = Db::table('game')->where('gameid',$game_id)->find();
        return $game;
    }

    public function editgame($game_id, $name, $gameimg, $intro,$startdate,$enddate) {
        $result = Db::table('game')
            ->where('gameid', $game_id)
            ->update([
                'gamename'  => $name,
                'intro' => $intro,
                'gameimg' =>  $gameimg,
                'startdate'=>$startdate,
                'enddate'=>$enddate,
            ]);

        return $result;
    }
    public function editgame2($game_id, $name, $intro,$startdate,$enddate) {
        $result = Db::table('game')
            ->where('gameid', $game_id)
            ->update([
                'gamename'  => $name,
                'startdate'=>$startdate,
                'enddate'=>$enddate,
                'intro' => $intro,
            ]);

        return $result;
    }

    public function deleteGame($game_id) {
        $result =  Db::table('game')->delete($game_id);
        return $result;
    }

    public function addGame($admin_id, $name, $src, $intro,$startdate,$enddate) {
        $club_id = Db::table('admin')->where('adminid',$admin_id)->find()['clubid'];
        $data = ['gamename' => $name, 'gameimg' => $src, 'intro'=>$intro,
            'clubid'=>$club_id,'startdate'=>$startdate,'enddate'=>$enddate];
        $result = Db::table('game')->insert($data);
        return $result;
    }
}